const router = require('koa-router')()
const {EahartsData} =require('../models/echartsData')
router.prefix('/setData')

// 添加数据
router.post('/addData',async ctx=>{
  const data =ctx.request.body
  try {
    await EahartsData.create(data)
      ctx.body={
        code:200,
        msg:"添加成功"
      }
  } catch (error) {
    ctx.body={
        code:404,
        msg:error
    }
  }
})

// 查询数据
router.post('/getDta',async ctx=>{
  const {userId,typeName} =ctx.request.body
  try {
    const data= await EahartsData.find({$and:[{userId:userId},{typeName:typeName}]})
    if(data.length>0){
        ctx.body={
            code:200,
            msg:'ok',
            data:data
        }
    }else{
       ctx.status=404
       ctx.body={
        code:404,
        msg:'参数错误',
    }
    }
  } catch (error) {
    ctx.body={
        code:500011,
        msg:error,
    }
  }
 
 
})

module.exports = router